package net.lesscoding.consumer;

import net.lesscoding.common.Const;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.consumer.MessageSelector;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
import org.apache.rocketmq.common.consumer.ConsumeFromWhere;

/**
 * @author eleven
 * @date 2024/6/2 11:07
 * @apiNote
 */
public class FilterBySQLConsumer {
    public static void main(String[] args) throws Exception {
        DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("cg");
        consumer.setNamesrvAddr(Const.TS_NAME_SRV_ADDR_OS1);
        consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
        consumer.subscribe("filterBySqlTopic", MessageSelector.bySql("age <=6 and age >= 0"));
        consumer.registerMessageListener(
                (MessageListenerConcurrently) (msgs, context) -> {
                    msgs.forEach(System.out::println);
                    return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
                });
        consumer.start();
    }
}
